package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.request.MemberRequest;
import com.ruoyi.system.domain.vo.TbMemberVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbMember;
import com.ruoyi.system.service.ITbMemberService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-18
 */
@RestController
@RequestMapping("/business/member")
public class TbMemberController extends BaseController
{
    @Autowired
    private ITbMemberService tbMemberService;

    /**
     * 查询会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberRequest tbMember)
    {
        startPage();
        List<TbMemberVO> list = tbMemberService.selectTbMemberList(tbMember);
        return getDataTable(list);
    }

    /**
     * 导出会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:member:export')")
    @Log(title = "会员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberRequest tbMember)
    {
        List<TbMemberVO> list = tbMemberService.selectTbMemberList(tbMember);
        ExcelUtil<TbMemberVO> util = new ExcelUtil<TbMemberVO>(TbMemberVO.class);
        util.exportExcel(response, list, "会员管理数据");
    }

    /**
     * 获取会员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:member:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbMemberService.selectTbMemberById(id));
    }

    /**
     * 新增会员管理
     */
    @PreAuthorize("@ss.hasPermi('business:member:add')")
    @Log(title = "会员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMember tbMember)
    {
        return toAjax(tbMemberService.insertTbMember(tbMember));
    }

    /**
     * 修改会员管理
     */
    @PreAuthorize("@ss.hasPermi('business:member:edit')")
    @Log(title = "会员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMember tbMember)
    {
        return toAjax(tbMemberService.updateTbMember(tbMember));
    }

    /**
     * 删除会员管理
     */
    @PreAuthorize("@ss.hasPermi('business:member:remove')")
    @Log(title = "会员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbMemberService.deleteTbMemberByIds(ids));
    }

    @GetMapping(value = "/getById/{id}")
    public AjaxResult getById(@PathVariable("id") Long id){
        return success(tbMemberService.getById(id));
    }

    @GetMapping("/getMemberList")
    public AjaxResult getMemberList(){
        return success(tbMemberService.getMemberList());
    }
}
